/**
 * 注册类js v2.0.0
 * @author: Jie.
 * @date: 2020-12-15
 */
var JCode = {
	register(moduls){
		//核心js注册
		if(!moduls) 
			return console.log("moduls is null!")
		for(var i of moduls) {
			switch (i){
				case 'config':
					let p9config = require("@/common/config/p9-config")
					console.log("P9version:" + p9config['p9version'])
					uni['p9version'] = p9config['p9version']
					uni['config'] = p9config 
					break
				case 'api':
					uni['api'] = require("@/common/config/api-config")
					break
				case 'core':
					uni['core'] = require("@/common/js/core")
					break
				case 'simpleData':
					uni['simpleData'] = require("@/common/js/data")
					break
				case 'flow':
					uni['flow'] = require("@/components/su-system/flow/flow")
					break
				case 'doc':
					uni['doc'] = require("@/components/su-system/attachment/attachment")
					break
				case 'dialog':
					uni['dialog'] = require("@/components/su-dialog/dialog")
					break
				case 'sutils':
					uni['sutils'] = require("@/common/js/utils")
					break
				default:
					break;
			}
		}
		console.log("Suapp:regsiter ['"+moduls.join("','")+"']")
	},
	registerUtils(Vue){
		
		Vue.prototype.$mainColor = "#33a0d6"
		
		/*根据*/
		uni.zoomSize = uni.getStorageSync("suFontZoom")|| 1.0
		Vue.prototype.getZoom = ()=>{
			return uni.zoomSize
		}
		
		/*普通处理时间与日期*/
		Vue.prototype.handleTime = (value, type) => {
			if(typeof value == "number") {
				return uni.sutils.formatDate(value, type == 'date' ? "yyyy-MM-dd" : "yyyy-MM-dd hh:mm")
			}else {
				let date = uni.sutils.stringToDate(value, type == "date"? "yyyy-MM-dd": "yyyy-MM-ddThh:mm:ss.fff")
				return uni.sutils.formatDate(date, type == 'date' ? "yyyy-MM-dd" : "yyyy-MM-dd hh:mm")
			}
		}
		/*字符串至日期*/
		Vue.prototype.stringToDate = (value,type)=> {
			if (value) {
				let date = uni.sutils.stringToDate(value, type == "date"? "yyyy-MM-dd": "yyyy-MM-ddThh:mm:ss.fff")
				return uni.sutils.formatDate(date, type == 'date' ? "yyyy-MM-dd" : "yyyy-MM-dd hh:mm")
			}else {
				return ""
			}
		}
		
		/*金额加逗号*/
		Vue.prototype.priceFormat = (s,n)=>{
			return uni.sutils.priceFormat(s,n)
		}
		
		/*金额转换*/
		Vue.prototype.handleNumber = (num)=>{
			return uni.sutils.formatNumber(num)
		}
		
		/*打开页面*/
		Vue.prototype.openPage = (url)=>{
			return uni.core.openPage(url)
		}
		
		Vue.prototype.redirectPage = (url)=>{
			uni.redirectTo({
				url:url
			})
		}
		
		/*关闭页面*/
		Vue.prototype.closePage = ()=>{
			return uni.navigateBack()
		}
	}
}

module.exports = JCode
